package com.ruoyi.web.controller.system;

import java.text.SimpleDateFormat;
import java.util.*;

import com.ruoyi.system.service.IShuttleLineService;
import com.ruoyi.system.service.IShuttleZhandianService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ShuttleOrder;
import com.ruoyi.system.service.IShuttleOrderService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2022-04-15
 */
@Controller
@RequestMapping("/system/order")
public class ShuttleOrderController extends BaseController
{
    private String prefix = "system/order";

    @Autowired
    private IShuttleOrderService shuttleOrderService;

    @Autowired
    private IShuttleLineService shuttleLineService;

    @Autowired
    private IShuttleZhandianService shuttleZhandianService;


   /* @RequiresPermissions("system:order:view")*/
    @GetMapping()
    public String order()
    {
        return prefix + "/order";
    }

    /**
     * 查询【请填写功能名称】列表
     */
    //@RequiresPermissions("system:order:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ShuttleOrder shuttleOrder)
    {
        startPage();
        List<ShuttleOrder> list = shuttleOrderService.selectShuttleOrderList(shuttleOrder);
        return getDataTable(list);
    }

    @PostMapping("/chaxunlist")
    @ResponseBody
    public TableDataInfo chaxunlist(@RequestParam("lineid") String lineid,
                                    @RequestParam("bancheshijian") String bancheshijian,
                                    @RequestParam("shiduan") String shiduan)
    {
        startPage();
        List<Map<String,Object>> list = shuttleOrderService.selectChaxunList(lineid,bancheshijian,shiduan);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("system:order:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ShuttleOrder shuttleOrder)
    {
        List<ShuttleOrder> list = shuttleOrderService.selectShuttleOrderList(shuttleOrder);
        ExcelUtil<ShuttleOrder> util = new ExcelUtil<ShuttleOrder>(ShuttleOrder.class);
        return util.exportExcel(list, "【请填写功能名称】数据");
    }

    /**
     * 新增【请填写功能名称】
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存【请填写功能名称】
     */
    //@RequiresPermissions("system:order:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ShuttleOrder shuttleOrder)
    {
        shuttleOrder.setOrderid(UUID.randomUUID().toString());
        shuttleOrder.setLinename(shuttleLineService.selectShuttleLineById(shuttleOrder.getLineid()).getName());
        shuttleOrder.setZhandianname(shuttleZhandianService.selectShuttleZhandianById(shuttleOrder.getZhandianid()).getName());
        shuttleOrder.setYuyueshijian(new Date());

        Calendar calendar = new GregorianCalendar();
        calendar.setTime(new Date());
        calendar.add(calendar.DATE, 1);

        shuttleOrder.setBancheshijian(calendar.getTime());
        shuttleOrder.setStatus((long)1);
        return toAjax(shuttleOrderService.insertShuttleOrder(shuttleOrder));
    }

    /**
     * 修改【请填写功能名称】
     */
    @GetMapping("/edit/{orderid}")
    public String edit(@PathVariable("orderid") String orderid, ModelMap mmap)
    {
        ShuttleOrder shuttleOrder = shuttleOrderService.selectShuttleOrderById(orderid);
        mmap.put("shuttleOrder", shuttleOrder);
        return prefix + "/edit";
    }

    /**
     * 修改保存【请填写功能名称】
     */
    @RequiresPermissions("system:order:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ShuttleOrder shuttleOrder)
    {
        return toAjax(shuttleOrderService.updateShuttleOrder(shuttleOrder));
    }

    /**
     * 删除【请填写功能名称】
     */
/*    @RequiresPermissions("system:order:remove")*/
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(shuttleOrderService.deleteShuttleOrderByIds(ids));
    }
}
